4. debugging tools (watchlists, trace, breakpoints)
在本课程中,我们将看到法院系统提供的一些附加工具,这些工具将帮助您开发和调试程序。
In this lesson, we will see some additional tools that are provided by court system that will help you develop and debug your program.
因此,从 Cotsis 的起始页开始,让我们创建一个新项目和一个标准项目。
So starting from the start page of Cotsis, let's create a new project and a standard project for us.
例如,我们将此测试称为测试一。
And let's call this test one, for instance.
我们将在这里编写一些简单的代码,我们可以选择标准控制器和结构文本为标准或您。
We will write some simple code over here, we can select the standard controller and the structure text to be standard or you.
现在,我们将实际看到可用于帮助您进行开发和缩减的工具。
And right now, we will see actually for tools that can be used for that will help you in developing and debulking.
因此,让我们从编写一些简单的代码开始。
So let's start in our Pyo you by writing some simple some really simple code them.
因此,让我们在这里添加一个计数器变量和整数变量。
So let's add that right here, a counter variable and integer variable.
那也在这里。
And that's also right over here.
让我们计算一下玻利安变量和减量交易量变量。
Let's please count up Bolian variable and account down volume variable.
我们只是写一些东西以便能够看到它。
We are just writing something in order to be able to see it.
那么,让我们在这里写一些非常简单的代码。
So and let's write over here some really simple code.
让我们来看看。
Let's see.
如果向上计数为 true,则 counter 应等于 counter 加一。
If you count up is true, then counter should be equal to counter plus one.
相反,如果倒计时为真,则计数器应等于计数器减一。
As if instead, if countdown is true, then counter should be equal to counter minus one.
这是一个非常简单的程序,简单的代码。
This is a really simple program, simple code.
我们还在这里添加一个该变量,再次添加一个布尔变量。
And let's also over here a that variable and again, a boolean variable.
让我们在这里,如果重置,则计数器应等于零。
And let's right down here, if reset, then counter shall be equal to zero.
好的。
OK.
现在,如果我们进入模拟模式并上网。
So right now, if we go in simulation mode and go online.
我们将能够通过这个非常简单的程序与这个程序进行交互。
We will be able to interact with this program, with this really simple program.
让我们开始你会看到计数等于零。
Let's start you will see count of being equal to zero.
如果我说可行的话数到七。
If I said count up viable through seven.
您会看到计数器会增加。
You will see the counter will be increasing.
如果我将其设置为强制,它就会停止。
If I set it to force, it will stop.
如果我说 come down 等于 true,那么它就会倒退。
If I said come down equal to true, it would go backward.
如果我说有一个变量,那么它就会变成零。
And if I said there is a variable, that would become zero.
因此,我想与您讨论的第一条规则是观察列表,您可以通过进入观察列表来创建观察列表,您将有四个不同的可能观察列表。
So the first rule I want to talk to you about is this is the watch list and you can create a watch list by going in over here in the watch and you will have four different possible watch lists.
如果您单击“观看一个”,您将在此处看到此窗口。
And if you click watch one, you will see this window over here.
在这个窗口中,您可以简单地在此处设置一个变量,并且您将能够在在线时实际监视并更改它。
And in this window, you can simply had a variable over here and you will be able to actually monitor it and change it while you are online.
例如,如果我就在这里,p.l.c.
So if, for instance, I were I right over here, p.l.c.
下划线 PFG 表示倒计时,我将在这里看到倒计时变量,就像在 PRC 声明窗口中看到的那样。
underscore PFG that count down, I will see over here the countdown variable in the same way that I see in the PRC the declaration window.
唯一的区别是,如果我关闭窗口并且移动到另一个可能的另一个窗口,我仍然会在这里看到它。
The only difference is that if I close the window and if I move to another possible another window, I would still be having this over here.
例如,我还可以在这里添加计数器,我会看到它,这样我就可以开始倒计时,我会看到我实际上可以强制和监视任何变量的所有内容。
For instance, I could also add the counter over here and I will see it so I can start counting down and I will see everything I actually can force and monitor any variable.
如果您在不同的人中有多个变量,在不同的设备中使用,在您想要同时监视的不同的全局变量列表中,这非常有用。
And this is quite useful if you have multiple variables in different people, use in different devices, in different global variable lists that you want to monitor at the same time.
因此,通过这种方式,使用监视列表,您可以创建自己想要查看的变量列表,并实际对它们进行排序并按照您喜欢的顺序放置它们。
So in this way, using the watchlist, you are able to create your own list of variables that you want to look at and actually order them and place them in the order that you prefer.
有时,这对于拥有自己的一组来自现有电力使用的变量子集非常有帮助。
And sometimes this is this is very helpful to have to have your own set of both your subset of variables from existing power use endless.
这些是您对他们的观察名单。
So these are the watch list you have for them.
您可以简单地在其中之一之间进行更改并打开不同的菜单等等。
You can simply change between one or the other and open different menus and so on.
这是一个非常简单的工具并且非常容易使用。
And this is quite a simple tool and very easy to use.
现在我将向您展示另一个非常重要的工具。
Now I will show you another very important tool.
这真的非常非常有帮助。
And this is really, really helpful.
为了什么?
For what?
呃,用于调试并查看程序如何工作。
Uh, for debugging and seeing how your program works.
所以这个工具被称为 The Trace,您可以在您的 p.l.c. 中添加跟踪。
So this tool is called The Trace, and you can add a trace in your p.l.c.
即使您在线使用某个程序,也可以进行配置。
configuration even if you are online on a program.
所以如果我。
So if I.
正确的。
Right.
单击应用程序,单击添加对象,然后选择跟踪。
Click on the application, click add object and I select the trace.
我可以在这里添加一条痕迹。
I can add over here a trace.
这是一个以图形方式监控变量的工具。
This is a tool to monitor variables graphically.
我现在就可以选择名字。
I can select the name right now.
我可以简单地称之为跟踪。
I can simply call this trace.
在这里你会看到这个痕迹。
And over here you will have this trace.
跟踪只是通过变量的图表。
The trace is simply through the graph of the of your variables.
因此,您可以在这里添加要监控的不同变量,并为其创建图表。
So over here you can add the different variables that you want to monitor, that you want to create a graph of.
实际上你需要在这里设置一些东西。
And you need actually to set a few things over here.
因此,在这里,我们通过单击此处的添加变量来添加一些变量。
So over here, let's add some variables by clicking over here on the add variables.
在此菜单中,您可以选择变量以及变量的颜色和其他图形选项。
And in this menu, you can select your variables and the color and other graphical options for your variables.
例如,我可能想绘制我们放置的所有变量的图表。
So, for instance, I may want to graph all the variables that we placed.
让我们看看这张图。
So let's see this graph.
柜台。
The the counter.
对不起。
Sorry.
让我们回到这里吧。
Let's go back over here.
计数器变量。
The counter variable.
然后我可以单击此处进行跟踪并单击添加变量。
Then I can click over here and trace and click on add variables.
我就这样,我把圣经加到这里来。
I will in this way, I will add the Bible down here.
假设这会下划线 PFG 正在计数。
Let's say that this goes to underscore PFG is count up.
再次,让我们添加另一个变量,是的,您强调了倒计时和强变量 p.l.c.。
Again, let's add another variable, yes, you underscore that count down and the strong and variable p.l.c.
强调重置。
underscore that reset.
好的,我们有这四个变量,我认为我们不需要在树中设置。
OK, so we have these four variables and I don't think that we need to set up in the trees.
您需要单击此处阈值上的轨迹。
You need to click on the trace on the threshold over here.
您需要选择一个任务,跟踪将在该任务上进行 Synchronoss,因此,如果您有一个具有特定周期时间的任务,则跟踪将对该周期时间之后的所有变量进行采样。
You need to select a task that will be on which there the trace will be Synchronoss, which so if you have a task going with a certain cycle time, the trace will sample all the variables following that cycle time.
所以在这里,我们只有主要任务。
So over here, we only have the main task.
如果我在这里选择主要任务,这意味着在主要任务的每个周期,跟踪都会向该段落添加一个点。
And if I select the main task over here, this means that at every cycle of the main task, the trace will add a point to to that paragraph.
我们快完成了,还有另一件重要的事情,我们需要提前过去。
We are almost done, just one other important thing, we need to go over here in advance.
您可以在此处选择所需的测量数量,在每个结束周期中可以在此处选择多少个周期,以及将有多少测量。
You can select over here how many measures you want, how many cycles your you can select over here in the every end cycle, how much measures there will be.
所以如果我选择一年,我每个周期都会有一个衡量标准。
So if I select one year, I will have a measure every cycle.
如果选择几个,我将在这里每两个周期进行一次测量。
If a select few, I will have a measure every two cycles over here.
任务时间为 20 毫秒。
The task is cédula 20 milliseconds.
因此,您将看到跟踪采样时间的第三年的周期时间实际上是什么。
So you will see what will be actually this the cycle time of year three of your sampling time of your trace.
然后在这里您可以选择跟踪的缓冲区大小。
Then over here you can select the buffer size for the trace.
所以现在我们正在选择将保留在跟踪中的样本数量。
So right now we are selecting the number of samples that will be kept in the trace.
因此,如果我看到 100 个样本、1000 个样本,我们将在跟踪中保留每个变量的 1000 个样本。
So if I see 100 samples, 1000 samples, we will keep 1000 samples of each variables in the trace.
这意味着 1000 乘以 20 毫秒,这样我们就可以保留最大 19 秒的内存,然后再减少 980 毫秒。
This means one thousand times twenty milliseconds so that we will keep whatever memory of a maximum memory of 19 seconds and then nine hundred and eighty milliseconds less, please.
假设是 10000。
This let's say 10000.
那是一段相当长的痕迹。
That is quite a long trace.
也就是三分二十秒。
That is three minutes and 20 seconds.
没关系。
That's OK.
所以现在我们的跟踪是配置器。
So right now our trace is configurator.
如果我走到这里就对了。
If I go over here and right.
单击在线并单击“下载跟踪”,我们可以看到我们的变量正在单个图表中跟踪。
Click while we are on line and click download trace, we can see that our variables are being traced in a single graph.
这实际上可能会令人困惑,因为不同的变量有不同的尺度。
This may actually be confusing because different variables have different scales.
所以通常你可以点击这里,对吗?
So typically you can click over here, right?
单击此处,然后单击转换为多通道。
Click over here and click convert to multichannel.
通过这种方式,您将在单个图表中看到每个变量的时间流。
In this way you will see the time flow of every variable in a single graph.
在这里,我们的计数器计数下降并重置。
So over here we have our acounter count up come down and reset.
在这里我停止了跟踪,所以如果我们现在进入我们的程序并将右侧的树拖到这里,让我们开始吧。
Here I stop the trace, so if we now go to our program and drag the trees on the right over here, let's.
把这个扔到这里,对吧,再次单击跟踪,然后单击下载跟踪法院系统,询问我们是否要删除设备上已存在的树。
Throw this over here, right, click on the trace again and click download trace a court system that asks us if we want to delete the trees that already exists on the device.
我们点击一下,确定。
Let's click, OK.
所以现在我们可以实时看到变量的值。
So right now we are seeing the values of the variables in real time.
您可以使用鼠标滚轮进行缩放,在此处您可以看到时间范围,在此处您可以看到数值。
You can zoom and with your mouse wheel and down here you see the time frames and over here you see the value values.
正如你所看到的,我们的布尔变量都是假的。
As you can see, our boolean variables are all false.
所以你可以在这里看到它们仍然是错误的。
So you can see here they are remaining false.
所以,如果你点击,你实际上可以随着轨迹自由移动。
So and then if you click, you can actually freely move with the with the trace.
如果你是对的。
And if you right.
单击并单击重置视图,您将在比赛填满时继续关注该比赛。
Click and click reset view, you will keep following the that race as it fills up.
你也可以在这里看到,塔的计数器可以等于负一七三。
And also you can see over here, the tower could counter is equal to minus one seven three.
就是这样。
So there it is.
例如,如果我们设置计数。
If, for instance, we set the count up.
巴博萨,确实,您实际上会看到计数达到谷值一并且计数器开始增加。
Barbossa, true, you will see actually the count up reaching the valley one and the counter starting to to increase.
如果我们开始这个,你会发现这变得错误。
If we start this, you will see this becoming false.
因此该值变为零并且计数器停止增加。
So the value becomes zero and acounter stops increasing.
以同样的方式,您可以减少计数器并在图表中看到它。
In the same way, you can decrease the counter and see it in the graph.
再说一次,你可以阻止它。
And again, you can stop it.
在这里,您还可以重置,您将看到计数器逐步归零,如果您单击树木并停止跟踪,我们将停止记录,您可以实际分析这里发生的情况。
And over here, you can also reset and you will see the counter going with a step to zero, if you click on the trees and stop trace, we will stop recording and you can actually analyze what happened here.
这是一个非常非常强大的工具,可以调试程序并查看实际发生的情况。
This is a very, very powerful tool to debug your program and to see actually what is happening.
当事情没有按计划进行时,它也非常有洞察力,因为您实际上可以看到每个周期正在发生的事情。
And it is also really insightful when something doesn't go according to plan because you can actually see cycle per cycle what is happening.
您实际上可以在这里放大到单个采样。
You can actually zoom up to the single sampling over here.
您实际上可以看到单次采样时间。
You can see actually the single sampling time.
而这其实是他无迹可寻的,而另一个强大的工具就是光标。
And this is actually something that he will not be able to to get through without a trace and another powerful tool is the cursor.
所以如果你是对的。
So if you right.
单击轨迹上的 ,然后单击光标,您将看到这个栏,它会显示您可以在轨迹上拖动,这实际上会显示您放置光标的所有变量的值。
Click on the on the trace and click on cursor, you will have this bar that will show you that you can drag across the trace, that will show you actually the value of all variables where you place the cursor.
例如,如果您想实际查看开始计数的周期,您可以到这里,您会看到在同一周期中,计数器为负一百七十二。
And for instance, if you want to see actually the cycle in which you started the count up, you can get over here and you will see that in the same cycle, the counter was minus one hundred seventy two.
同时,您可以到这里查看到达柜台之前的最后一个值是多少。
And at the same time, you can go over here and see what was the last value before you were at the counter.
那是272。
And it was 272.
这是非常非常强大的。
And this is very, very powerful.
如果您愿意,您还可以在此处添加跟踪触发器,这意味着现在我们通过单击并单击下载来手动开始这场比赛。
You can also add over here, if you wish, a trigger for the trace, meaning that right now we are starting this race manually by clicking and clicking download.
您还可以设置自动启动跟踪的条件。
And you are also able to have a condition that will start the trace automatically.
因此,如果我们在这里进行跟踪,您可以启用触发器,您可以选择一个将触发跟踪开始的变量。
So if we go over here and trace, you can enable trigger, you can select a variable that will trigger the the trace to start.
即使您有,呃,您也可以选择变量的正沿或正沿、正触发而不是负触发或两者,以实际启动跟踪记录。
Even if you have, uh, you can select a positive or a positive edge, positive trigger of the variable over a trigger that is negative or both to actually start the the trace recording.
因此,举例来说,如果您想开始计数以开始记录,当我们让 CPG 计数变量等于 true 时,我们可以在此处选择零的触发样本,以防止没有足够的样本。
So for instance, if you wanted to start counting to start recording, when we get our CPG count up variable equal to true, we can and over here you can select the trigger samples that there is zero not to have enough enough samples.
让我们选择积极触发广告。
Let's select the positive trigger ads.
我们点击一下,确定。
Let's click, OK.
现在我们有了带有触发变量的配置器 3。
So right now we have configurator 3s with the with the trigger variable.
因此,如果我们单击此处的下载,您将看到跟踪正在进行。
So if we click download over here, you will see that the trace is is going.
但如果我们设置计数变量,您会在这里看到,有一个黑色条,我们设置 10 秒来记录我们的跟踪。
But if we set the count up variable, you will see over here, there is this black bar and we set 10 seconds to record for our trace.
你会看到10秒后,这条路自动停止了。
And you will see that after 10 seconds, that way stops automatically.
如果您想跟踪发生的特定事件(可能是警报,可能是其他事件),这非常有用。
This is very useful is if you want to get a trace of a particular event occurring, maybe an alarm, maybe something else.
因此,您实际上可以将跟踪设置为在发生某种情况时停止。
So you can actually set the trace to stop when a certain condition occurs.
这也非常有帮助。
And this as well is very helpful.
所以现在我们已经看到了痕迹。
So right now we have seen the trace.
这是一个非常重要的工具。
This is a really important tool.
我们将在这个视频中看到另外两个工具,这个视频,以及第一个我们可以离线使用的工具。
We will see other two tools in this videos, this video, and the first one we can go offline.
第一个是交叉引用列表。
The first one is the cross-reference list.
也许我们已经看到了。
Maybe we have already seen it.
但是如果你继续使用一个变量,比如说计数器变量,你是对的,点击,你就可以浏览,然后你就可以浏览,交叉引用计数器。
But if you go on a variable, let's say the counter variable and you're right, click, you get to browse and you go to browse, cross-reference counter.
您将在此处看到将打开的菜单。
You will see this menu down here that will open.
这非常有用,因为它实际上会在代码中向您显示此处使用该变量的位置。
This is really useful because it will actually show you in the code wherever the variable is being used over here.
你在那里看到的。
You see it there.
该变量在这里声明。
The variable is declared over here it.
并且您还可以查看判决是写入还是读取,您可以看到 Barbossa 在代码一、二和三中写入了三次,并且还读取了两次一和二。
And you can also see if the verdict is written or read, you can see that Barbossa is written three times in the code one, two and three and is also read two times one and two.
同样在这里,我们可以看到变量正在跟踪中被读取。
And also over here, we can see that the variable is being read in the trace.
这是非常强大的,如果您想查看变量发生了什么,并且您有一个非常大且复杂的代码,那么跟踪正在发生的事情非常有用。
This is very powerful, if you want to see what is happening to your variables and if you have a really big and complex code, it is really useful to keep track of what is happening.
然后我将向您展示最后一个工具,它实际上存在于许多编程环境中,那就是断点。
Then I will show you one last tool that is actually present in many, many programming environments, and that is the break point.
断点只是一个占位符,您放置在某一行代码上,当程序到达该行时,它将停止程序的执行。
And the break point is simply a placeholder that you put on the on a certain line of code that will stop the execution of the program when the program gets to that line.
因此,例如,我可以通过单击并设置切换断点在第一行中放置一个断点。
So, for instance, I could place a breakpoint over here in this first line by clicking and setting toggle breakpoint.
你会看到它变成了红色,这意味着断点被放置在这里。
You will see that this has become red, the meaning that the breakpoint was placed over here.
现在这条线已经变成黄色了。
And right now the line has become yellow.
在这里你可以看到我们已经保持在断点上。
And over here you can see that we have held on breakpoint.
这意味着 CPU 现在处于停止状态,我们可以在此处使用此命令在程序中逐行移动。
This means that the CPU is now in a stop state and we can go use this commands over here to move line by line in our program.
因此,通过克服这一步或单击 FSN,我们实际上可以逐行移动并查看发生了什么。
So with this step overcome and or by clicking FSN, we can actually move line by line and see what is happening.
这对于拦截某些条件非常有用,可以实际一步一步地查看。
This could be quite useful to intercept some conditions, to actually see step by step.
但是您编写的代码在这里是这样做的。
But what the code that you wrote is doing so over here.
如果我按开始,我们将在下一个周期进入同一点。
If I press start, we will just get in the same point at the next cycle.
例如,如果护士将计数设置为 true,我就会走过去。
For instance, if a nurse set the count up equal to true and I step over.
你会看到,我们进入这一行,计数器现在等于七七千六十四,如果你跨过去,它就会加一。
You will see that we will enter this line and the counter is now equal to seven and seven thousand and sixty four, and if you step over, it will be increased by one.
如果继续下去,我们实际上可以为每一行手动执行此操作。
If we go on, we can actually do it manually for every single line.
然后,让我们将其设置为第四个,然后通过单击并开始断点来删除该断点。
And then again, let's set this the fourth and let's remove this break point by clicking and starting to break point.
如果我们现在就开始,PSC 就会开始。
If we start right now, the PSC is going.
这是。
It is.
例如,如果我们在第二行的此处放置一个断点。
And if, for instance, we place a breakpoint over here in the second line.
您将看到 CPU 仍在运行,并且在该断点处并未完全打开,这只是因为该行没有,呃,没有循环,因为计数可行是错误的。
You will see that the CPU is still running and it is not being whole turned on this breakpoint, and this is simply because this line is not, uh, is not cycling, because the count up viable is false.
例如,如果我将计数变量设置为 true,您将看到 PRC 的执行将在此行停止,并且每个周期都会发生这种情况,直到我也将其设置为止。
And if, for instance, I set the count up variables to true, you will see that the execution of the PRC will halt on this line and this will happen for every cycle until I set this also.
如果我开始,中华人民共和国就不会再停在这里。
Then if I start, the PRC will not halt here again.
当某些事情没有按您预期的方式工作时,这非常有用,可以逐行实际查看正在发生的情况以及您应该做什么。
This is quite useful when something is not working the way you intend to, to actually see line by line what is happening and what you should.
你应该小心使用这个程序和这个工具,因为如果你在真机上使用它可能会很危险,因为你实际上正在停止 CPU,你实际上正在停止任务的执行。
You should be careful with this program, with this tool, because it may be dangerous if you are doing using this on the on the real machine because you are actually stopping the CPU, you are actually halting the execution of your task.
因此,如果您正在处理的任务很重要,则该流程将不再处理,因为执行已更改。
So if your task was handling is something that was important, that process is no longer handled because the execution is altered.
所以我建议你只有在模拟环境中或者你没有使用真实设备并且处于不安全的情况下才使用断点。
So I recommend you to use the break point only when you are in a simulation environment or you're not using real devices and you are unsafe conditions.
在具有移动设备的真实机器上使用断点,其设备可能会很危险,我确实不建议这样做。
Using a breakpoint on a real machine with moving equipment, with their equipment that could be dangerous is really I do not suggest it is.
所以我们在视频中看到了四个主要工具。
So this where we saw in this video, we saw four main tools.
我们看到观察列表减少了交叉引用列表和断点。
We saw the watch list decrease the cross-reference list and the break point.
这些是非常有用的工具和类,它们将帮助您开发程序并修复程序的错误。
These are very useful tools and classes they will help you develop and the bug your programs.